var logiticsList = [],
	xpopupLogics = null,
	callback = null,
	displayId = '',
	selectIndex = -1,
	selectItem = null;

$(() => {
	queryLogisticsCompany(res => {
		if (res.code == 200) {
			logiticsList = res.data;
		} else {

		}
	})
})

onLogisticsChange = (e, index) => {
	selectIndex = index;
	let item = toObject(e.dataset.item);
	selectItem = item;
}

onLogisticsConfirm = (e) => {
	$(`#${displayId}`).html(selectItem.name);
	layer.close(xpopupLogics);
	callback(selectItem);
}

selectLogistics = (mdisplayId, mCallback) => {
	if (logiticsList.length == 0) {
		showToast('暂无数据');
		return
	}
	callback = mCallback;
	displayId = mdisplayId;
	let logisticsCompanyHtml = `<section class="form_pick_container">`;
	logiticsList.forEach((e, i) => {
		let id = e.code;
		let name = e.name;
		let checked = selectIndex == i ? 'checked' : '';
		logisticsCompanyHtml += `<label class="form_select_radio" for="${id}">
									<input type="radio" class="form_select_input" ${checked} name="pick_logistics" data-item="${toObjectStr(e)}" id="${id}" onchange="onLogisticsChange(this,'${i}')"/>
									<span class="checkmark"></span>
									<span class="form_select_content">${name}</span>
								</label>`;
	})
	logisticsCompanyHtml += `</section>
							<section class="col">
								<button class="btn_primary" onclick="onLogisticsConfirm(this)">确定选择</button>
							</section>`;
	//页面层
	xpopupLogics = layer.open({
		type: 1,
		title: '请选择',
		shadeClose: true,
		content: logisticsCompanyHtml,
		anim: 'up',
		style: 'position:fixed; bottom:0; left:0; width: 100%; padding:0px 0; border:none;border-top-left-radius: 1rem;border-top-right-radius: 1rem;'
	});
}
